<%@page import="service.CollectService"%>
<%@page import="entities.GoodsEntity"%>
<%@page import="entities.CartEntity"%>
<%@page import="service.OrderService"%>
<%@page import="entities.OrderEntity"%>
<%@page import="service.UserService"%>
<%@page import="entities.UserEntity"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";

	String userName = (String) session.getAttribute("userName");
	String action = request.getParameter("action");
	UserEntity user = new UserEntity();
	//订单数据
	List<OrderEntity> orderList = new ArrayList<OrderEntity>();
	if (userName == null) {
		response.sendRedirect("../logReg.jsp?action=login");
	} else {
		user = UserService.getUser(userName);
		//获得订单数据
	}
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>订单历史-<%=user.getName()%></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js">
	
</script>
<script src="js/GlobalFunction.js" type="text/javascript"></script>
<script type="text/javascript" src="<%=basePath%>user/js/order.js">
	
</script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/cart.css">
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>user/css/user.css">


<style type="text/css">

/*订单信息*/
.orderInfo {
	border-bottom: 1px solid #ccc;
	padding: 5px;
}

.orderInfo div {
	margin-bottom: 3px;
}

.orderInfo span {
	color: #15ADFF;
	font-size: 14px;
}
/*订单号*/
.orderInfo span.orderNo {
	color: red;
	font-weight: bold;
	font-size: 20px;
	margin-bottom: 10px;
}

.orderInfo .detail {
	font-size: 12px;
	padding: 2px;
	margin-right: 5px;
	color: white;
	background-color: #15ADFF;
}

.orderInfo .detail:hover {
	background-color: #7CDAEF;
	color: red;
}
</style>
</head>

<body>
	<jsp:include page="../header.jsp"></jsp:include>
	<div id="userName" style="height: 30px;"><%=userName%></div>
	<div id="action" style="display: none;"><%=action%></div>
	<div class="center">
		<div class="place">
			<a href="user/index.jsp"><%=userName%>的账户 </a> &gt; 订单与购物车
		</div>
		<div class="leftPanel">
			<div class="userInfo" id="UserInfo">
				<ul>
					<li><a title="设置头像" href="user/userInfo.jsp?action=head"><span
							id="userHead" style="display: none;"><%=user.getHeadImgUrl()%></span><img
							src="<%=user.getHeadImgUrl()%>" alt="头像"> </a>
						<h3>
							[<%=user.getName()%>]
						</h3> 性别：<%=user.getSex()%> <br /><%=user.getCampus()%>校区</li>
					<li><a class="name">手机号码：</a><a class="value"><%=user.getTel()%></a>
					</li>
					<li><a class="name">送餐地址：</a><a class="value"><%=user.getAddr()%></a>
					</li>
					<li><a class="name">注册时间：</a><a class="value"><%=user.getRegTime()%></a>
					</li>
				</ul>
			</div>
			<span class="seperateLine"></span>


			<div class="thirdNav">
				<ul>
					<li id="history"><a
						href="user/orderHistory.jsp?action=history">历史订单记录</a>
					</li>
					<li id="notDelivery"><a
						href="user/orderHistory.jsp?action=notDelivery">未发货订单</a>
					</li>
					<li id="collect"><a
						href="user/orderHistory.jsp?action=collect">我的收藏夹</a>
					</li>
					<li id="count"><a href="user/orderHistory.jsp?action=count">历史交易统计</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="rightPanel" id="orderList">
			<%
				if ("history".equals(action)) {
			%>
			<div class="panelTitle">
				<a>历史订单记录</a>
			</div>
			<%
				} else if ("notDelivery".equals(action)) {
					//获得未发货的订单
					List<OrderEntity> orderL = new ArrayList<OrderEntity>();
					orderL = OrderService.getNotDelivery(userName);
			%>
			<div class="panelTitle">
				<a>未发货订单</a><br />
				<div style="font-size: 10px;">鉴于平台特性，只提供最近一周的可能未发货的订单查询</div>
			</div>
			<%
				for (int i = 0; i < orderL.size(); i++) {
			%>
			<div class="orderInfo">
				<div>
					订 单 号 ：<span class="orderNo"><%=orderL.get(i).getNo()%></span>
				</div>
				<div style="float: left;width: 48%;">
					收 餐 人 ：<span><%=orderL.get(i).getToUser()%></span>
				</div>
				<div>
					送餐地址：<span><%=orderL.get(i).getToAddr()%></span>
				</div>
				<div style="float: left;width: 48%;">
					订餐日期：<span><%=orderL.get(i).getTime()%></span>
				</div>
				<div>
					付款信息：<span><%=orderL.get(i).getState() == 1 ? "未付款" : "已付款"%></span><a
						class='detail' href='javascript:void(0);return false;'
						onclick='showDetail(<%=orderL.get(i).getId()%>)'
						style='float:right;'>详情</a>
				</div>
				<!-- 详情 -->
				<div id='<%=orderL.get(i).getId()%>' class='cart'
					style='display:none;'>
					<div class="cart_products">
						<table width="100%">
							<tbody>
								<tr>
									<th width="50%">产品</th>
									<th width="25%">数量</th>
									<th width="25%">价格</th>
								</tr>
								<%
									List<CartEntity> cartL = orderL.get(i).getCartList();
											double totalPrice = 0d;
											for (int j = 0; j < cartL.size(); j++) {
												if(cartL.get(j).getItemState()<3){
												totalPrice += cartL.get(j).getItemCount()
														* cartL.get(j).getGoodsPrice();
								%>
								<tr class="cart_item">
									<td class="name"><div style="position: relative;">
											<a
												href="goodsDetail.jsp?goodsId=<%=cartL.get(j).getGoodsId()%>"
												target="_blank"><%=cartL.get(j).getGoodsName()%></a> <a
												class="sellerName"
												href="menu.jsp?sellerId=<%=cartL.get(j).getSellerId()%>"
												target="_blank">【<%=cartL.get(j).getSellerName()%>】</a>
											<div class="itemTime"><%=cartL.get(j).getItemTime()%></div>
										</div>
									</td>
									<td align="center" class="number_box"><%=cartL.get(j).getItemCount()%>(单价：<span>¥<%=cartL.get(j).getGoodsPrice()%></span>)</td>
									<td class="count_price_box"><span>¥<%=cartL.get(j).getItemCount()
								* cartL.get(j).getGoodsPrice()%></span>
									</td>
								</tr>
								<%	}
									}
								%>
								<tr class="no_border">
									<td colspan="6" class="count">应付总额 ：<span
										class="totalPrice">¥ <span><%=totalPrice%></span> </span>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<%
				}
				} else if ("count".equals(action)) {
			%>
			<div class="panelTitle">
				<a>交易统计</a>
			</div>
			<div>
				请选择统计区间： <select name="times" id="Times" class="textBox">
					<option value="all">全部</option>
					<option value="month">最近一个月</option>
					<option value="week" selected="selected">最近一周</option>
				</select>
			</div>
			<div class="orderInfo">
				<div class="orderInfo">您  <span id="TimesVal">时间</span> 的交易统计如下：</div>
				<div>
					您总共定外卖的次数 ：  <span id="CountAllVal"> 0 </span>  次 。
				</div>
				<div>
					总花费 ： ￥  <span id ="PayAllVal">0.00</span>  ， 平均每次花费   ￥ <span id="PayAvgVal"> 0.0 </span>  。
				</div>
				<div>
					您最喜欢的商家是 ：   <span id="FavSelVal">**</span>  ，您去了该商家   <span id="FSCountVal"> 0 </span>  次 。
				</div>
				<div>
					您最喜欢的菜肴是 ：  <span id="FavGoodsVal">**</span> ，您购买了商品   <span id="FGCountVal"> 0 </span>  次 。
				</div>
			</div>
			<%
				}else if("collect".equals(action)){
			%>
			<div class="panelTitle">
				<a>我的收藏夹</a>
			</div>
			<div class="cart_other_products">
				<div class="mall_box" id="featured_star" style="display: block;">
					<ul class="product_list" id="product_list_star">
					<%
					List<GoodsEntity> goodsList = new ArrayList<GoodsEntity>();
					goodsList = CollectService.selectAll(userName); 
					for(GoodsEntity goods:goodsList) {%>
						<li class="cross_sale_deal">
							<div class="pic">
								<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>" target="_blank"><img src="<%=goods.getImageUrl() %>" width="160"
									height="160"> </a>
							</div>
							<div class="name">
								<a href="goodsDetail.jsp?goodsId=<%=goods.getId() %>" target="_blank"><%=goods.getName() %></a>
							</div>
						    <div class="price">
								<span>¥<%=goods.getPrice() %></span><button  onclick="deleteCollect(<%=goods.getId()%>);" id="delete">移除</button>
							</div>
							<div  onclick="readyBuy(<%=goods.getId()%>);" id="buy" class="button">加入购物车</div>
						</li>
						
					<%} %>
				</ul>
			</div>
		</div>
		<%} %>
		</div>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
